<template>
    <div>
        <iview-table
                ref="table"
                :span1="19"
                :span2="5"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :defaultFilters="queryModel.defaultFilters"
                v-on="{changeTotalSize:changeTotalSize,events:events,changeSelect:changeSelect}">
        </iview-table>
        <br>
        <iview-page
                style="margin-bottom: 200px"
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
        </iview-page>
        <Modal v-model="showAdd" @on-ok="save" ok-text="保存" :closable='false' :mask-closable=true :width="800">
            <h3 slot="header" style="color:#2D8CF0">请填写生理学数据</h3>
            <Row>
                <Col span="22" offset="1">
                    <Form :model="formItem" :label-width="120">
                        <Card :bordered="false" :dis-hover="true">
                            <FormItem label="洁面">
                                <CheckboxGroup v-model="cleans" @on-change="changeCleanFace">
                                    <Checkbox label="卸妆油"></Checkbox>
                                    <Checkbox label="起泡洗面奶"></Checkbox>
                                    <Checkbox label="无泡洗面奶"></Checkbox>
                                    <Checkbox label="温水"></Checkbox>
                                    <Checkbox label="冷水"></Checkbox>
                                </CheckboxGroup>
                            </FormItem>
                            <FormItem label="洁面后等待时间">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.cleanFaceWaitTime" placeholder="" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">&nbsp;</Col>
                                </Row>
                            </FormItem>
                            <FormItem label="检测室温度">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.temperature" placeholder="" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">&nbsp;</Col>
                                </Row>
                            </FormItem>
                            <FormItem label="检测室湿度">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.humidity" placeholder="" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">&nbsp;</Col>
                                </Row>
                            </FormItem>
                            <FormItem label="气候">
                                <RadioGroup v-model="formItem.climate">
                                    <Radio label="1">晴</Radio>
                                    <Radio label="2">阴</Radio>
                                    <Radio label="3">雨</Radio>
                                    <Radio label="4">雪</Radio>
                                </RadioGroup>
                            </FormItem>
                            <FormItem label="临床诊断">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.clinicalDiagnosis" placeholder="" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">&nbsp;</Col>
                                </Row>
                            </FormItem>
                            <FormItem label="水分">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.moisture" placeholder="请填写百分位数" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <table>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">M：</td>
                                                        <td style="padding: 0px 20px 0px 20px"><20y:>74</td>
                                                        <td style="padding: 0px 20px 0px 20px">20-30y:>69</td>
                                                        <td style="padding: 0px 20px 0px 20px">30-40y:>69</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td style="padding: 0px 20px 0px 20px">40-50y:>64</td>
                                                        <td style="padding: 0px 20px 0px 20px">50-60y:>54</td>
                                                        <td style="padding: 0px 20px 0px 20px">>60y:>54</td>
                                                    </tr>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">F：</td>
                                                        <td style="padding: 0px 20px 0px 20px"><20y:>64</td>
                                                        <td style="padding: 0px 20px 0px 20px">20-30y:>59</td>
                                                        <td style="padding: 0px 20px 0px 20px">30-40y:>59</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td style="padding: 0px 20px 0px 20px">40-50y:>54</td>
                                                        <td style="padding: 0px 20px 0px 20px">50-60y:>44</td>
                                                        <td style="padding: 0px 20px 0px 20px">>60y:>44</td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="油脂">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.grease" placeholder="请填写百分位数" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <table>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">MT：</td>
                                                        <td style="padding: 0px 20px 0px 20px"><20y:60-80</td>
                                                        <td style="padding: 0px 20px 0px 20px">20-30y:55-75</td>
                                                        <td style="padding: 0px 20px 0px 20px">30-40y:50-70</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td style="padding: 0px 20px 0px 20px">40-50y:45-65</td>
                                                        <td style="padding: 0px 20px 0px 20px">50-60y:40-60</td>
                                                        <td style="padding: 0px 20px 0px 20px">>60y:35-55</td>
                                                    </tr>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">MU：</td>
                                                        <td style="padding: 0px 20px 0px 20px"><20y:40-60</td>
                                                        <td style="padding: 0px 20px 0px 20px">20-30y:37-57</td>
                                                        <td style="padding: 0px 20px 0px 20px">30-40y:34-54</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td style="padding: 0px 20px 0px 20px">40-50y:31-51</td>
                                                        <td style="padding: 0px 20px 0px 20px">50-60y:28-48</td>
                                                        <td style="padding: 0px 20px 0px 20px">>60y:25-45</td>
                                                    </tr>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">FT：</td>
                                                        <td style="padding: 0px 20px 0px 20px"><20y:50-70</td>
                                                        <td style="padding: 0px 20px 0px 20px">20-30y:45-65</td>
                                                        <td style="padding: 0px 20px 0px 20px">30-40y:40-60</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td style="padding: 0px 20px 0px 20px">40-50y:35-55</td>
                                                        <td style="padding: 0px 20px 0px 20px">50-60y:30-50</td>
                                                        <td style="padding: 0px 20px 0px 20px">>60y:25-45</td>
                                                    </tr>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">FU：</td>
                                                        <td style="padding: 0px 20px 0px 20px"><20y:35-55</td>
                                                        <td style="padding: 0px 20px 0px 20px">20-30y:32-52</td>
                                                        <td style="padding: 0px 20px 0px 20px">30-40y:29-49</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td style="padding: 0px 20px 0px 20px">40-50y:26-46</td>
                                                        <td style="padding: 0px 20px 0px 20px">50-60y:23-43</td>
                                                        <td style="padding: 0px 20px 0px 20px">>60y:20-40</td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="弹性">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.elasticity" placeholder="请填写百分位数" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <table>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px"><20y:>40</td>
                                                        <td style="padding: 0px 20px 0px 20px">20-30y:>38</td>
                                                        <td style="padding: 0px 20px 0px 20px">30-40y:>35</td>
                                                    </tr>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">40-50y:>31</td>
                                                        <td style="padding: 0px 20px 0px 20px">50-60y:>26</td>
                                                        <td style="padding: 0px 20px 0px 20px">>60y:>20</td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="酸碱值">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.ph" placeholder="请填写百分位数" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <table>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">4.2-5.8</td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="黑色素">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.melanin" placeholder="请填写百分位数" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <table>
                                                    <tr>
                                                        <td style="padding: 0px 20px 0px 20px">I:0-15 II:0-20 III:0-20 IV:20-39 V:30-69 VI:>50</td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                        </Card>
                        <Card :bordered="false" :dis-hover="true">
                            <p slot="title">
                                测量项目：皮肤屏幕 | 测量指标：TEWL
                            </p>
                            <FormItem label="鼻尖">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.twelNose" placeholder="请输入测量值" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <23g/hm²
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="下巴">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.twelChin" placeholder="请输入测量值" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <16g/hm²
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="前额/颧骨">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.twelCheekbones" placeholder="请输入测量值" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <14g/hm²
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="面颊">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.twelCheek" placeholder="请输入测量值" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <13g/hm²
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="口周">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.twelMouthWeeks" placeholder="请输入测量值" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <17g/hm²
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                        </Card>
                        <Card :bordered="false" :dis-hover="true">
                            <p slot="title">
                                测量项目：皮肤超声
                            </p>
                            <FormItem label="Gain">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.gain" placeholder="请输入测量值" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                0-4
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="Skin Thickness(μm)">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.skinThickness" placeholder="请输入测量值" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <16g/hm²
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="Intensity Score">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.intensityScore" placeholder="请输入测量值" style="width: 100%"></Input>
                                    </Col>
                                    <Col align="center" span="3">
                                        <Poptip trigger="hover" placement="right" width="100%">
                                            <a href="#"><Icon type="information-circled"></Icon> 参考值</a>
                                            <div class="api" slot="content">
                                                <14g/hm²
                                            </div>
                                        </Poptip>
                                    </Col>
                                </Row>
                            </FormItem>
                            <FormItem label="请填写测量部位">
                                <Row>
                                    <Col span="21">
                                        <Input v-model="formItem.skinUltrasound" type="textarea" :autosize="{minRows: 5,maxRows: 5}" placeholder="请输入内容..."></Input>
                                    </Col>
                                </Row>
                            </FormItem>
                        </Card>
                    </Form>
                </Col>
            </Row>
        </Modal>
    </div>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    import iviewPage from '@/view/common/page/Page.vue';
    export default {
        components: {
            iviewTable,
            iviewPage
        },
        props: {
            menuId: {
                type: [Number, String],
                default: -1
            },
            type: {
                type: [Number, String],
                default: -1
            }
        },
        data () {
            return {
                showAdd: false,
                selectRows: [],
                cleans: [],
                baseURL: '/user/physiological',
                formItem: {
                    id: '',
                    patientId: '',
                    complaintId: '',
                    cleanFace: '',
                    cleanFaceWaitTime: '',
                    temperature: '',
                    humidity: '',
                    climate: '',
                    clinicalDiagnosis: '',
                    moisture: '',
                    grease: '',
                    elasticity: '',
                    ph: '',
                    melanin: '',
                    twelNose: '',
                    twelChin: '',
                    twelCheekbones: '',
                    twelCheek: '',
                    twelMouthWeeks: '',
                    gain: '',
                    skinThickness: '',
                    intensityScore: '',
                    skinUltrasound: ''
                },
                queryModel: {
                    // 网关代理路径(必须)+资源路径(可选)
                    baseURL: '/user/physiological',
                    defaultFilters: [
                        // {'field': 'patient_id', 'value1': -1, 'operate': '=='},
                        // {'field': 'complaint_id', 'value1': -1, 'operate': '=='}
                    ]
                },
                dataModel: {
                    menuId: 6305,
                    columns: [
                        {
                            type: 'selection',
                            width: 60,
                            align: 'center'
                        },
                        {
                            title: '诊断时间',
                            key: 'creationTime',
                            type: 'date',
                            sortable: true,
                            render: (h, params) => {
                                return h('span', this.$moment(params.row.creationTime).format('YYYY年MM月DD日'))
                            }
                        },
                        {
                            title: '临床诊断',
                            key: 'clinicalDiagnosis'
                        }
                    ],
                    order: 'id desc'
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 10,
                    pageSizeOpts: [10, 50, 100, 500]
                }
            };
        },
        methods: {
            events (item) {
                let path = item.path
                if (path === 'add') {
                    this.add()
                } else if (path === 'edit') {
                    this.edit()
                } else if (path === 'delete') {
                    this.delete()
                } else if (path === 'print') {
                    this.print()
                }
            },
            add () {
                this.cleans = []
                this.formItem.id = ''
                this.$bus.init(this.formItem)
                this.showAdd = true
            },
            edit () {
                if (this.selectRows.length === 1) {
                    this.formItem = this.selectRows[0]
                    this.showAdd = true
                } else {
                    this.$bus.alert('warning', '请选择一条记录')
                }
            },
            delete () {
                if (this.selectRows.length > 0) {
                    let ids = []
                    for (let row of this.selectRows) {
                        ids.push(row.id)
                    }
                    this.$Modal.confirm({
                        title: '操作提示',
                        content: '<p>确认删除'+ids.length+'条记录?</p>',
                        onOk: () => {
                            this.doDelete(ids)
                        }
                    })
                } else {
                    this.$bus.alert('warning', '请至少选择一条记录')
                }
            },
            doDelete (ids) {
                let url = this.baseURL + '/delete'
                this.$ajax.post(url, ids).then((response) => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '删除成功')
                        this.refresh()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                });
            },
            print (){
                if (this.selectRows.length === 1) {
                    let url = this.$store.state.app.WEBROOT + '/user/print/physiological?id=' + this.selectRows[0].id
                    window.open(url)
                } else {
                    this.$bus.alert('warning', '请选择一条记录')
                }
            },
            save () {
                if (this.formItem.id === '') {
                    this.formItem.patientId = this.$store.state.app.patientId
                    this.formItem.complaintId = this.$store.state.app.complaintId
                }
                this.formItem.cleanFace = this.cleans.toString()
                let url = this.baseURL + '/saveOrUpdate'
                this.$ajax.post(url, this.formItem).then(r => {
                    let {code, msg} = r.data
                    if (code === 0) {
                        this.$bus.alert('success', '保存成功')
                        this.showAdd = false
                        this.refresh()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            handleChange (newTargetKeys) {
                this.keys = newTargetKeys;
            },
            refresh () {
                this.queryModel.defaultFilters.length = []
                if (this.$store.state.app.patientId) {
                    this.queryModel.defaultFilters.push({'field': 'patient_id', 'value1': this.$store.state.app.patientId, 'operate': '=='})
                }
                if (this.$store.state.app.complaintId) {
                    this.queryModel.defaultFilters.push({'field': 'complaint_id', 'value1': this.$store.state.app.complaintId, 'operate': '=='})
                }
                this.$refs.table.refresh()
            },
            changeCleanFace (values) {
                this.cleans = values
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
            },
            changePageSize (pageSize) {
                this.pageModel.pageSize = pageSize
            },
            init () {
                this.refresh()
            }
        },
        mounted () {
            // this.init()
        }
    }
</script>

<style>

</style>
